| Total Complexity | 6 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Step, StepResult } from 'prosemirror-transform'; |
||
| 8 | export default class SetDocAttrStep extends Step { |
||
| 9 | constructor(key, value, stepType = 'SetDocAttr') { |
||
| 10 | super(); |
||
| 11 | this.stepType = stepType; |
||
| 12 | this.key = key; |
||
| 13 | this.value = value; |
||
| 14 | } |
||
| 15 | |||
| 16 | apply(doc) { |
||
| 17 | this.prevValue = doc.attrs[this.key]; |
||
| 18 | /* eslint-disable-next-line no-param-reassign */ |
||
| 19 | doc.attrs[this.key] = this.value; |
||
| 20 | return StepResult.ok(doc); |
||
| 21 | } |
||
| 22 | |||
| 23 | invert() { |
||
| 24 | return new SetDocAttrStep(this.key, this.prevValue, 'revertSetDocAttr'); |
||
| 25 | } |
||
| 26 | |||
| 27 | map() { |
||
| 28 | return null; |
||
| 29 | } |
||
| 30 | |||
| 31 | toJSON() { |
||
| 32 | return { |
||
| 33 | stepType: this.stepType, |
||
| 34 | key: this.key, |
||
| 35 | value: this.value, |
||
| 36 | }; |
||
| 37 | } |
||
| 38 | |||
| 39 | static fromJSON(json) { |
||
| 40 | return new SetDocAttrStep(json.key, json.value, json.stepType); |
||
| 41 | } |
||
| 42 | } |
||
| 43 |